@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './token.less';

@cascader-picker-prefix-cls: ~'@{kd-prefix}-cascader-picker';
@cascader-menus-prefix-cls: ~'@{kd-prefix}-cascader-menus';
@cascader-menu-prefix-cls: ~'@{kd-prefix}-cascader-menu';
@icon-prefix-cls: ~'@{kd-prefix}icon';

.@{cascader-picker-prefix-cls} {
  position: relative;
  outline: none;
  cursor: pointer;
  background: @cascader-bg-color;

  &.disabled {
    .@{cascader-picker-prefix-cls}-input {
      cursor: not-allowed;
      border-color: @color-border-strong;

      .@{kd-prefix}-input-suffix,
      i[class*='@{icon-prefix-cls}'] {
        color: @cascader-disabled-color;
      }
    }
  }

  &-label {
    box-sizing: border-box;
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 20px;
    padding: 0 24px 0 0;
    line-height: 20px;
    transform: translateY(-50%);
    .ellipsis;
  }

  &-input {
    background-color: transparent;
    transition: all 0.2s;

    > input {
      color: transparent !important;
      cursor: pointer;
    }

    &.expand {
      i[class*='@{icon-prefix-cls}'] {
        transform: rotate(180deg);
      }
    }

    .@{kd-prefix}-input-suffix,
    i[class*='@{icon-prefix-cls}'] {
      transition: all 0.2s;
    }
  }

  &.allowClear:hover {
    .@{cascader-picker-prefix-cls}-close {
      opacity: 1;
      visibility: visible;
      transition: all 0.2s;
      transform: scale(1) translateY(-50%);
    }

    .@{kd-prefix}-input-suffix {
      opacity: 0;
      visibility: hidden;
      transition: all 0.1s;
    }
  }

  &-close {
    position: absolute;
    top: 50%;
    right: 0;
    opacity: 0;
    cursor: pointer;
    visibility: hidden;
    color: @cascader-clear-color;
    transition: all 0.1s;
    transform-origin: 50% 50%;
    transform: scale(0.9) translateY(-50%);

    &:hover {
      color: @cascader-clear-color-hover;
    }
  }
}

.@{cascader-menus-prefix-cls} {
  .reset-component;
  color: @cascader-color;
  border-radius: @cascader-radius-size;
  font-size: @cascader-font-size;
  font-weight: @cascader-font-weight;
  background-color: @cascader-bg-color;
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.3);
  opacity: 1;
  visibility: visible;
  z-index: @z-index-popper;

  &.hidden {
    opacity: 0;
    visibility: hidden;
  }

  .@{cascader-menu-prefix-cls} {
    display: inline-block;
    height: @cascader-height;
    min-width: @cascader-menu-min-width;
    margin: 0;
    padding: @cascader-menu-padding-vertical 0;
    overflow-y: auto;

    &:not(:first-child) {
      border-left: 1px solid @color-border-strong;
    }

    &-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 @cascader-menu-item-padding-horizontal;
      line-height: @cascader-menu-item-height;
      cursor: pointer;

      &:not(.disabled, .selected):hover {
        background-color: @cascader-hover-bg-color;
        transition: all calc(@duration-promptly - 0.1s) @motion-ease;
      }

      &.disabled {
        color: @cascader-disabled-color;
        cursor: not-allowed;
      }

      &.selected {
        color: @cascader-selected-color;
        background-color: @cascader-selected-bg-color;
      }

      &-label {
        width: @cascader-menu-item-label-width;
        .ellipsis;
      }

      &.last .@{cascader-menu-prefix-cls}-item-label {
        width: calc(@cascader-menu-item-label-width + 20px);
      }

      .@{kd-prefix}-cascader-checkbox {
        margin-right: 5px;
      }
    }
  }

  .@{kd-prefix}-empty {
    padding: 10px 0 20px;
  }
}

.@{kd-prefix}-cascader {
  &-bordered:not(.@{kd-prefix}-cascader-multiple) {
    .@{cascader-picker-prefix-cls}-label {
      padding-left: 9px;
    }
    .@{cascader-picker-prefix-cls}-close {
      right: 10px;
    }
  }

  &-bordered&-multiple {
    border: 1px solid #d9d9d9;
    padding-left: 8px;
    border-radius: 2px;

    .@{kd-prefix}-cascader-suffix {
      right: 9px;
      top: 50%;
      transform: translateY(-50%);
    }
  }

  &-multiple {
    transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
    min-height: 30px;
    max-height: 100px;
    color: #212121;
    display: flex;
    cursor: pointer;
    box-sizing: border-box;
    overflow-x: hidden;
    position: relative;
    border-bottom: 1px solid #d9d9d9;
    background: @cascader-bg-color;

    &:not(.@{kd-prefix}-cascader-disabled):focus {
      border-color: @cascader-selected-color;
      outline: none;
    }
  }

  &-multiple-wrapper {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    padding: 1px 28px 1px 0;
    overflow-y: auto;
  }

  &-placeholder {
    position: absolute;
    font-size: @middle-font-size;
    color: @cascader-placeholder-color;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  &-suffix {
    right: 0;
    position: absolute;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
  }

  &-selection-tag {
    max-width: 100%;
  }

  &-multiple:hover &-icon-clear {
    opacity: 1;
  }

  &-icon {
    &-arrow {
      display: inline-flex;
      align-items: center;
      vertical-align: middle;
      &-up {
        transform: rotate(180deg);
        transition: transform calc(@transition-duration - 0.1s) @ease;
      }

      &-down {
        transform: rotate(0deg);
        transition: transform calc(@transition-duration - 0.1s) @ease;
      }
    }

    &-clear {
      opacity: 0;
      z-index: 1;
      position: absolute;
      background: #fff;
      transition: opacity 0.15s ease;
      color: @cascader-clear-color;
      &:hover {
        color: @cascader-clear-color-hover;
      }
    }
  }

  &-tag {
    &-describe {
      font-size: 12px;
      height: 20px;
      line-height: 18px;
      margin: 2px 8px 2px 0;
      user-select: none;

      &-content {
        display: inline-flex;
        align-items: center;
        padding: 0 7px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        border: 1px solid #ccc;
        color: #212121;
      }
    }
  }

  &-disabled {
    cursor: not-allowed;

    .@{kd-prefix}-cascader-picker-label {
      color: @cascader-disabled-color;
    }

    .@{kd-prefix}-cascader-picker-input {
      background-color: @cascader-disabled-color-background;

      > input {
        background-color: @cascader-disabled-color-background;
      }
    }

    &.@{kd-prefix}-cascader-multiple {
      background-color: @cascader-disabled-color-background;
    }

    .@{kd-prefix}-cascader-suffix {
      color: @cascader-disabled-color;
    }

    .@{kd-prefix}-cascader-tag-describe-content {
      color: @cascader-tag-disabled-color;
      border-color: @cascader-tag-disabled-color;
    }
  }

  &-picker:not(&-disabled):hover,
  &-expand {
    .kd-input-wrapper {
      border-color: @cascader-g-color-border-focus;
    }
  }

  &-multiple:not(&-disabled):hover,
  &-expand {
    border-color: @cascader-g-color-border-focus;
  }
}

.@{kd-prefix}-cascader-rtl {
  direction: rtl;
  .@{cascader-picker-prefix-cls}-label {
    right: 0;
    left: auto;
    padding: 0 0 0 24px;
  }
  .@{cascader-picker-prefix-cls}-close {
    left: 0;
    right: auto;
  }
  &.@{kd-prefix}-cascader-bordered:not(.@{kd-prefix}-cascader-multiple) {
    .@{cascader-picker-prefix-cls}-label {
      padding-left: 24px;
      padding-right: 9px;
    }
    .@{cascader-picker-prefix-cls}-close {
      left: 10px;
      right: auto;
    }
  }
  &.@{kd-prefix}-cascader-multiple {
    padding-left: 0;
    padding-right: 8px;
    .@{kd-prefix}-cascader-multiple-wrapper {
      padding: 1px 0 1px 28px;
    }
    .@{kd-prefix}-cascader-suffix {
      left: 0;
      right: auto;
      margin-right: 8px;
      margin-left: 0;
    }
  }
  &.@{kd-prefix}-cascader-bordered&.@{kd-prefix}-cascader-multiple {
    padding-right: 8px;
    padding-left: 0;
    .@{kd-prefix}-cascader-suffix {
      left: 9px;
      right: auto;
    }
  }
  .@{cascader-menu-prefix-cls} {
    &:not(:first-child) {
      border-right: 1px solid @color-border-strong;
      border-left: none;
    }
    &-item {
      .@{kd-prefix}-cascader-checkbox {
        margin-left: 5px;
        margin-right: 0;
      }
    }
  }
}
